/**
* This file is part of OntoApplications (project linked with OntoCompoFramework)
*
* Copyright (C) 2011 -  Christian Brel
*
* @author   Main    Christian Brel
**/
package applications.staticmap.fc.lib;

import java.util.Observable;

import ontocompo.api.OntoCompoIntrospection;

import org.objectweb.fractal.fraclet.annotations.Component;
import org.objectweb.fractal.fraclet.annotations.Interface;

import applications.staticmap.fc.api.StaticMapService;

@Component(provides = {@Interface(name = "staticmapservice", signature = applications.staticmap.fc.api.StaticMapService.class), @Interface(name = "observable", signature = ontocompo.api.Observable.class), @Interface(name = "ontocompointrospection", signature = ontocompo.api.OntoCompoIntrospection.class)})
public class StaticMapServiceImpl extends Observable implements StaticMapService, ontocompo.api.Observable, OntoCompoIntrospection {
	
	private int zoom;
	private int width;
	private int height;
	private String mapType;
	private String location;
	
	private String uid;
	private org.objectweb.fractal.api.Component c;

	public StaticMapServiceImpl() {
		this.uid = "applications.staticmap.fc.lib.StaticMapServiceImpl";
		
		this.zoom = 7;
		this.width = 390;
		this.height = 400;
		this.mapType = "roadmap";
	}

	@Override
	public String getHtmlStaticMap() {
		// TODO Auto-generated method stub
		String center = this.location.replace(' ', '+');
		
		String url = "http://maps.google.com/maps/api/staticmap?";
        url += "center=" + center;
        url += "&amp;zoom=" + this.zoom;
        url += "&amp;size=" + this.width + "x" + this.height;
        url += "&amp;maptype=" + this.mapType;
        url += "&amp;sensor=false";

        String html = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>";
        html += "<html><head></head><body>";
        html += "<img src='" + url + "'>";
        html += "</body></html>";
        
        return html;
	}

	@Override
	public void setLocation(String location) {
		// TODO Auto-generated method stub
		this.location = location;
		setChanged();
		notifyObservers();
	}

	@Override
	public void setMapType(String mapType) {
		// TODO Auto-generated method stub
		this.mapType = mapType;
		setChanged();
		notifyObservers();
	}

	@Override
	public void setSize(int width, int height) {
		// TODO Auto-generated method stub
		this.width = width;
		this.height = height;
		setChanged();
		notifyObservers();
	}

	@Override
	public void setZoom(int zoom) {
		// TODO Auto-generated method stub
		this.zoom = zoom;
		setChanged();
		notifyObservers();
	}
	
	public void clearChanged() {
		super.clearChanged();
	}
	
	public void setChanged() {
		super.setChanged();
	}

	@Override
	public org.objectweb.fractal.api.Component getFractalComponent() {
		// TODO Auto-generated method stub
		return this.c;
	}

	@Override
	public void setFractalComponent(org.objectweb.fractal.api.Component c) {
		// TODO Auto-generated method stub
		this.c = c;
	}
	
	@Override
	public String getUid() {
		// TODO Auto-generated method stub
		return this.uid;
	}

	@Override
	public void setUid(String uid) {
		// TODO Auto-generated method stub
		this.uid = uid;
	}
}
